#ifndef _WSTR_H_
#define _WSTR_H_

// Rev 2

#ifdef WIN32
#	define WIN32_LEAN_AND_MEAN
#	include <windows.h>
#else
#	include <wchar.h>
#endif

#include <iostream>
#include <vector>
#include <cstdlib>

#include "exception.h"

namespace wstr {

//// Conversions ////

// Convert string to wstring
std::wstring toWide(std::string str);

// Convert wstring to string
std::string toNonWide(std::wstring wstr);

// Convert to integer
int toInt(std::wstring str);


struct ConversionError : util::Exception {
	ConversionError(std::wstring str) : util::Exception(str) {}
};


//// String utils ////

// Remove whitespace from beginning and end of a string
std::wstring strip(std::wstring str, const wchar_t *wspace=L" \t\r\n");

// Split string at first encounter of a character in a given separator list, sep.
// Return values:
//     head = part before the separator,
//     sep  = the separating character,
//     tail = the remaining part of the string.
// If separator is not found,
//     head = str,
//     sep  = "",
//     tail = ""
struct WStringPartition {
	std::wstring head, sep, tail;
};
WStringPartition partition(std::wstring str, const wchar_t *sep);

// Split string into a list of strings, splitting at each encounter of a
// character in the given separator list.
std::vector<std::wstring> split(std::wstring str, const wchar_t *sep);


}

// Transform a non-user-given string into a wstring.
//   Only for system errors and the like.
const std::wstring W(const wchar_t *wstr); 
const std::wstring W(const char *str);

// Convenience functions for combining strings
std::wstring operator+(std::wstring &wstr1, std::wstring &wstr2);
std::wstring operator+(std::wstring &wstr1, const wchar_t *wstr2);
std::wstring operator+(const wchar_t *wstr1, std::wstring &wstr2);

#endif
